<template>
  <div id="resourceManagement">
    <div id="tabelTitle">
      新客户跟踪
    </div>
    <div id="table">
      <avue-crud
        v-model="form"
        :search.sync="searchForm"
        :page.sync="page"
        :data="tableData"
        :table-loading="tableLoading"
        :option="tableOption"
        @on-load="getList"
        @search-change="searchChange"
        @refresh-change="refreshChange"
        @size-change="sizeChange"
        @current-change="currentChange"
        @row-update="handleUpdate"
        @row-save="handleSave"
        @row-del="rowDel"

      >
        <template slot-scope="{disabled,size}" slot="stuNameSearch">
          <div class="inputStyle">
            <el-input placeholder="请输入姓名或手机号" :disabled="disabled" :size="size" style="width:50%; "
                      v-model="searchForm.keyWord"></el-input>
          </div>
        </template>
        <template slot="menu" slot-scope="{row,size}">
          <el-button type="primary" :size="size" @click="addTrack(row)">添加跟踪记录</el-button>
        </template>
      </avue-crud>
    </div>
    <el-dialog
      title="新增跟踪记录"
      :visible.sync="dialogVisible"

      width="60%"
    >
      <div>
        <avue-form ref="formForm" v-model="formForm" :option="formOption"   @reset-change="emptytChange" @submit="submit">
        </avue-form>
      </div>

    </el-dialog>
  </div>
</template>

<script>
import tableMixins from "@/mixins/tableMixin.vue"
export default {
  name: "newCustomerTracking",
  mixins: [tableMixins],
  data(){
    return{
      form: {},
      data: [],
      //访问接口前缀
      url: "yuanjiu.testnew/tn-task-list",
      searchForm: {},
      // 表格参数
      tableOption: {
        labelWidth:200,
        searchSpan:6,
        border: true,
        index: false,
        indexLabel: '序号',
        indexWidth: 50,
        stripe: true,
        align: 'center',
        searchMenuSpan:10,
        // searchLabelWidth: 100,
        calcHeight: 300,
        dialogWidth: 900,
        menuWidth: 200,
        menu: true,
        menuAlign: 'center',
        refreshBtn: false,
        columnBtn: false,
        searchShowBtn: false,
        addBtn: true,
        selection: true,
        rowKey: "id",
        emptyBtn: true,
        editBtn: false,
        viewBtn: true,
        delBtn: false,
        emptyBtnText: "重置",
        editBtnText: "修改",
        maxHeight: 645000,
        searchSize: "medium",
        column: [
          {
            prop: 'stuName',
            label: '姓名',
            search: true,
            searchLabelWidth:'50',
          },
          {
            prop: 'priorLvl',
            label: '优先级',
            type:'select',
            search:true,
            span:24,
            searchLabelWidth:'60',
            props: {
              label: 'name',
              value: 'code'
            },
            dicData: [
              {
                name: '低',
                code: 1
              }, {
                name: '中',
                code: 2
              }, {
                name: '高',
                code: 3
              }],
            rules: [{
              required: true,
              message: "请选择优先级",
              trigger: "change"
            }]
          },
          {
            prop: 'productId',
            label: '培训类别',
            type: "select",
            dicUrl: '/yuanjiu.testnew/tn-product/listTnProduct',
            dicMethod: 'post',
            props: {
              label: "productName",
              value: "productId",
              res: "result"
            },
            search:true,
            searchLabelWidth:'80',
            rules: [{
              required: true,
              message: "请选择培训类别",
              trigger: "change"
            }]
          },
          {
            prop: 'phoneNum',
            label: '手机号',
          },
          {
            prop: 'area',
            label: '地域',
          },
          {
            prop: 'chanelCode',
            label: '渠道',
            search:true,
            searchLabelWidth:'50',
            type: "select",
            dicUrl: '/yuanjiu.testnew/yj-config/getConfigByCode?itmCode=CHANEL_CODE',
            props: {
              label: "itmName",
              value: "itmVal",
              res: "result"
            },
            rules: [{
              required: true,
              message: "请选择渠道",
              trigger: "change"
            }]
          },
          {
            prop: 'sourceCode',
            label: '来源途径',
            type: "select",
            dicUrl: '/yuanjiu.testnew/yj-config/getConfigByCode?itmCode=SOURCE_CODE',
            props: {
              label: "itmName",
              value: "itmVal",
              res: "result"
            },
          },
          {
            prop: 'status',
            label: '进展情况',
            type: "select",
            searchLabelWidth:'80',
            search:true,
            dicUrl: '/yuanjiu.testnew/yj-config/getConfigByCode?itmCode=PRO_STS',
            props: {
              label: "itmName",
              value: "itmVal",
              res: "result"
            }
          },
          {
            prop: 'allocTime',
            label: '分配时间',
            type: "datetime",
          },
        ]
      },
      addUrl: "insertOrUpdate",
      listUrl: 'pageTnTaskListNew',
      distributionList: [],
      //新增跟踪记录表单
      dialogVisible:false,
      formForm: {},
      formOption:{
        column: [
          {
            label: "跟踪类型",
            prop: "flowTypeCode",
            type: "select",
            display:true,
            labelWidth:120,
            span: 12,
            dicUrl: '/yuanjiu.testnew/yj-config/getConfigByCode?itmCode=FLOW_TYPE',
            props: {
              label: 'itmName',
              value: 'itmVal',
              res: 'result'
            },
            rules: [{
              required: true,
              message: "请选择类型",
              trigger: "change"
            }],
            filterable: true
          },
          {
            label: "跟踪时长",
            prop: "duration",
            span: 12,
            labelWidth:120,

          },
          {
            label: "跟踪结果",
            prop: "resultCode",
            type: "select",
            span: 12,
            labelWidth:120,
            dicUrl: '/yuanjiu.testnew/yj-config/getConfigByCode?itmCode=FLOW_RSLT',
            props: {
              label: 'itmName',
              value: 'itmVal',
              res: 'result'
            },
            rules: [{
              required: true,
              message: "请选择跟踪结果",
              trigger: "change"
            }],
            filterable: true,
            change: ({value,column}) => {
              if(value==102){
                this.formOption.column[4].display =true
                this.formOption.column[5].display =true
              }
              else {
                this.formOption.column[4].display =false
                this.formOption.column[5].display =false
              }
              // console.log('值改变',value,column,)
            },
          },
          {
            label: "优先级",
            prop: "deptId",
            type: "select",
            labelWidth:120,

            span: 12,
            dicUrl: '/yuanjiu.testnew/yj-config/getConfigByCode?itmCode=PRIOR_LVL',
            props: {
              label: 'itmName',
              value: 'itmVal',
              res: 'result'
            },
            rules: [{
              required: true,
              message: "请选择类型",
              trigger: "change"
            }],
            filterable: true
          },
          {
            label: "入学时间",
            prop: "entranceStartTime",
            type: "date",
            labelWidth:120,

            display:false,
            format:'yyyy-MM-dd',
            valueFormat:'yyyy-MM-dd',
            span: 12,
            rules: [{
              required: true,
              message: "请选择类型",
              trigger: "blur"
            }],
          },
          {
            label: "入学班级",
            prop: "classId",
            labelWidth:120,

            type: "select",
            display:false,
            dicUrl: '/yuanjiu.testnew/tn-class/listTnClass',
            dicMethod: 'post',
            props: {
              label: 'className',
              value: 'classId',
              res: 'result'
            },
            span: 12,
            rules: [{
              required: true,
              message: "请选择类型",
              trigger: "blur"
            }],
          },
          {
            label: "跟踪记录",
            labelWidth:120,

            prop: "remark",
            type: "textarea",
            span: 24,
            rules: [{
              required: true,
              message: "请输入跟踪记录",
              trigger: "blur"
            }],
          },
          {
            label: "下次跟踪时间",
            prop: "nextFlowTime",
            type: "datetime",
            format:'yyyy-MM-dd HH:mm:ss',
            valueFormat:'yyyy-MM-dd HH:mm:ss',
            span: 24,
            labelWidth:120,
            rules: [{
              required: true,
              message: "请选择下次跟踪时间",
              trigger: "blur"
            }],
          }
        ]
      }
    }
  },
  methods:{
    addTrack(row){
      // console.log('添加跟踪记录')
      this.formForm.stuId =row.stuId
      this.dialogVisible =true
    },
    emptytChange(){
    },
    //提交记录
    submit(form,done){
      this.$httpService.post('/yuanjiu.testnew/tn-task-list/insertOrUpdate', this.formForm).then(res => {
        this.$message.success('操作成功')
        this.$refs.formForm.resetForm()
        // console.log(this.formForm)
        done()
        this.dialogVisible = false
      })
    }
  }
}
</script>

<style scoped>
.inputStyle{
  width: 600px;
}
@media only screen and (max-width: 1600px){
  .inputStyle{
    width: 530px;
  }
}
@media only screen and (max-width: 1500px){
  .inputStyle{
    width: 430px;
  }
}
@media only screen and (max-width: 1366px){
  .inputStyle{
    width: 330px;
  }
}
@media only screen and (max-width: 900px){
  .inputStyle{
    width: 600px;
  }
}

</style>

